﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NCT.Framework;
using VISS.API.Users;


namespace VISS.Web.Frontend.Guest {
    public partial class GuestSearchlite : System.Web.UI.Page {
        public string PageTitle { get; set; }
        public string Keywords { get; set; }
        public string Description { get; set; }

        protected int TotalRecord;
        protected List<UserSrhResEnt> SearchResult { get; set; }

        protected void Page_Load(object sender, EventArgs e) {

            UserContext userContext = LoginFactory.GetCurrentUser();
            if (userContext != null) {
                Response.Redirect("/profile?u=" + userContext.UserKey);
                return;
            }

            short gender;
            short cityID;
            int fromAge = ConvertUtils.ToInt(Request.QueryString["fromage"], -1);
            int toAge = ConvertUtils.ToInt(Request.QueryString["toage"], -1);

            gender = ConvertUtils.ToShort(Request.QueryString["gender"], -1);
            cityID = ConvertUtils.ToShort(Request.QueryString["city"], -1);

            EvtNoelUserSrhEnt srhEnt = new EvtNoelUserSrhEnt();

            if (gender != -1) {
                srhEnt.Gender = (EUserGender)gender;
            }
            else {
                srhEnt.Gender = EUserGender.Unknown;
            }
            srhEnt.CityID = cityID;

            int temp;
            if ((fromAge > toAge) && fromAge > 0 && toAge > 0) {
                temp = fromAge;
                fromAge = toAge;
                toAge = temp;
            }

            if (fromAge > 0) {
                if (fromAge < 18) {
                    fromAge = 18;
                }
                srhEnt.ToBirthDate = new DateTime(DateTime.Now.Year - fromAge, 12, 31);
            }
            if (toAge > 0) {
                if (toAge > 90) {
                    toAge = 90;
                }
                srhEnt.FromBirthDate = new DateTime(DateTime.Now.Year - toAge, 1, 1);
            }
            srhEnt.GoOut = true;

            SearchResult = StructureMapFactory.GetInstance<IUserGeneralProfile>().QuickSearchForNoelEvent(srhEnt, EUserQuickSearchOrderType.Random, 1, 6, out TotalRecord);

            PageTitle = StringResources.SEO.TitleSearch + " | Khách | " + StringResources.SEO.TitleDefault;
            Description = StringResources.SEO.DescriptionDefault;
            Keywords = StringResources.SEO.KeywordsDefault;
        }
    }
}
